package weiyunsuan;

public class _06浮点数变二进制 {
    //给定一个浮点数，将此浮点数用其二进制表示
    public static void main(String[] args) {
        double num = 0.625;
        StringBuffer sb = new StringBuffer("0.");
        while (num > 0){
            double r = num * 2;
            //相乘后整数位有1
            if (r >= 1){
                sb.append("1");
                //消除掉整数位
                num = r - 1;
            }else {
                sb.append("0");
                num = r;
            }
            if (sb.length()>34){
                System.out.println("ERROR");
                break;
            }
        }
        System.out.println(sb.toString());
    }
}
